#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll rr() {
    ll s = 0, w = false, c = getchar();
    for (; !isdigit(c); c = getchar())
        w = w || c == '-';
    for (; isdigit(c); c = getchar())
        s = s * 10 + c - '0';
    return w ? -s : s;
}

// END OF HEADER

struct Node {
    int x, y;
    bool operator<(Node& o) const {
        return y < o.y;
    }
};

int main() {
    int n = rr();
    vector<Node> v(n);
    for (int i = 0; i < n; i++) {
        v[i].x = rr(), v[i].y = rr();
    }
    sort(v.begin(), v.end());
    int ans = 0, past = 0;
    for (int i = 0; i < n; i++) {
        if (v[i].x >= past) {
            past = v[i].y;
            ans++;
        }
    }
    printf("%d", ans);
    return 0;
}

